<!DOCTYPE html>
<html>
<head>
    <include file="./Application/Home/View/Tpl/head.html" />

    <include file="./Application/Home/View/Tpl/commjs.html" />

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <include file="./Application/Home/View/Tpl/header.html" />


    <input type="hidden" id="iscrack" name="iscrack" value="{$iscrack}">
    <input type="hidden" id="iswz" name="iswz" value="{$iswz}">
    <input type="hidden" id="isattack" name="isattack" value="{$isattack}">
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                首页
                <small>热点扫描</small>
            </h1>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="row">
                <div class="col-md-12">
                    <button class="btn pull-right  btn-success btn-lg" action="" id="scanstatus" name="scanstatus">
                        扫描状态读取中... ...
                    </button>
                </div>



            </div>
            <BR>
            <div class="row">
                <div class="col-md-12">
                    <div class="nav-tabs-custom">
                        <ul class="nav nav-tabs">
                            <li class="active" ><a href="#wifiap" data-toggle="tab">WiFi热点列表
                                <empty name="scanwifidata">
                                    <small class="label pull-right bg-green">0 台</small>
                                    <else />
                                    <small class="label pull-right bg-green scanwifidata">{:count($scanwifidata)} 台</small>
                                </empty>
                            </a></li>
                        </ul>
                        <div class="tab-content">
                            <div class="active tab-pane " id="wifiap">
                                <!-- Post -->
                                <div class="post">
                                    <div class="col-xs-12">
                                        <div style="float:  left" class="col-md-4">

                                            <div class="input-group input-group-sm">
                                                <input type="text" class="form-control" id="filtertxt">
                                                <span class="input-group-btn">
                                                  <button class="btn btn-info btn-flat"  id="search" type="submit">搜索</button>
                                                </span>
                                            </div>
                                        </div>

                                        <div style="float:  right">
                                            <button class="btn   btn-danger" id="clearwifi" name="clearwifi">
                                                <i class="fa  fa-trash-o"></i> 清空WiFi热点列表
                                            </button>
                                        </div>
                                        <BR>
                                        <BR>
                                        <div class="box" id="wifilist">
                                            <empty name="scanwifidata">
                                                尚未扫描到任何热点。
                                                <else />
                                                <table class="table table-hover">
                                                    <tbody>
                                                        <foreach name="scanwifidata" item="vo" key="k" >
                                                            <tr>
                                                            <if condition="$k%2 eq '0' ">
                                                                <div class="info-box ">
                                                                    <elseif condition="$k%2 eq '1' " />
                                                                    <div class="info-box  bg-bgray">
                                                            </if>

                                                            <span class="info-box-icon"> {$k+1}</span>
                                                            <div class="info-box-content">
                                                                <span class="info-box-text" style="font-size: 14px">
                                                                    MAC <strong>[{$vo['mac']}]</strong> &nbsp;&nbsp;&nbsp;
                                                                    | &nbsp;&nbsp;&nbsp;信道<strong>[{$vo['signalpath']}]</strong>&nbsp;&nbsp;&nbsp;
                                                                   &nbsp;&nbsp;
                                                                    |&nbsp;&nbsp;&nbsp;
                                                                    捕获日期 <strong>[
                                                                    {$vo['time']|substr=0,4}年{$vo['time']|substr=4,2}月
                                                                    {$vo['time']|substr=6,2}日
                                                                    {$vo['time']|substr=8,2}:{$vo['time']|substr=10,2}:{$vo['time']|substr=12,2} ]</strong>

                                                                    |设备名称[{$vo['devmodel']}]
                                                                    |版本号[{$vo['ver_name']}]
                                                                </span>

                                                                <span class="info-box-number" style="font-size: 24px">
                                                                    SSID:{$vo['ssid']}
                                                                    <span class="crackpwd" id="crackpwd{$vo['id']}">
                                                                         <if condition="$vo['crackpwd'] neq null ">
                                                                             (<small class=" ">密码：{$vo['crackpwd']}</small>)
                                                                         </if>
                                                                    </span>
                                                                    <input type="hidden" id="crackpwdval{$vo['id']}" value="{$vo['crackpwd']}">




                                                                    <span style="float: right">
                                                                        <button class="btn   btn-default getapsta"
                                                                                apmac="{$vo['mac']}"
                                                                                data-toggle="modal" data-target="#myModal">
                                                                            <i class="fa fa-eye"></i> 查看接入终端
                                                                        </button>

                                                                        <button class="btn   btn-info crackwifi"  type="button"
                                                                                myid="{$vo['id']}"
                                                                                xd="{$vo['signalpath']}" apmac="{$vo['mac']}"
                                                                                <if condition="$vo['iscrack'] eq '1' ">
                                                                                    action="stop"
                                                                                <else  />
                                                                                    action="start"
                                                                                </if>>

                                                                            <if condition="$vo['iscrack'] eq '1' ">
                                                                                正在破解中... ...
                                                                                <else  />
                                                                                开启破解
                                                                            </if>

                                                                        </button>

                                                                        <button class="btn   btn-success wzwifi"   type="button"
                                                                                myid="{$vo['id']}"
                                                                                xd="{$vo['signalpath']}" ssid="{$vo['ssid']}"
                                                                                <if condition="$vo['iswz'] eq '1' ">
                                                                                action="stop"
                                                                                <else  />
                                                                                action="start"
                                                                                </if>
                                                                                encrypt="{$vo['encryption']}" key="" apmac="{$vo['mac']}" >

                                                                            <if condition="$vo['iswz'] eq '1' ">
                                                                                正在伪装中
                                                                                <else  />
                                                                                开启伪装
                                                                            </if>
                                                                        </button>

                                                                        <button class="btn   btn-danger attackwifi" type="button"
                                                                                xd="{$vo['signalpath']}" apmac="{$vo['mac']}"
                                                                                <if condition="$vo['isattack'] eq '1' ">
                                                                                    action="stop"
                                                                                <else  />
                                                                                    action="start"
                                                                                </if>>
                                                                            <if condition="$vo['isattack'] eq '1' ">
                                                                                正在攻击中
                                                                                <else  />
                                                                                开启攻击
                                                                            </if>
                                                                        </button>
                                                                    </span>

                                                                </span>
                                                                <div class="progress">
                                                                    <div class="progress-bar" style="background:#e08e0b; width:  {-$vo['signalstrength']}%"> </div>
                                                                </div>
                                                                      <span class="progress-description">
                                                                         <if condition="$vo['encryption'] eq 'WPA-WPA2' ">
                                                                             <span class="label label-info">{$vo['encryption']}</span>
                                                                             <elseif condition="$vo['encryption'] eq 'WEP' " />
                                                                             <span class="label label-default">{$vo['encryption']}</span>
                                                                             <elseif condition="$vo['encryption'] eq 'OPEN' " />
                                                                             <span class="label label-danger">{$vo['encryption']}</span>
                                                                             <else />
                                                                             <span class="label label-primary">{$vo['encryption']}</span>
                                                                         </if>

                                                                          <span class="label label-primary">
                                                                               场强[{-$vo['signalstrength']}]
                                                                          </span>
&nbsp;
                                                                          <a class="btn getdistance"
                                                                             mac="{$vo['mac']}"  signalstrength="{-$vo['signalstrength']}">
                                                                            <i class="fa fa-repeat"></i> 距离[获取中]
                                                                          </a>
                                                                      </span>

                                                            </div><!-- /.info-box-content -->
                                                            </tr>


                                                        </foreach>
                                                    </tbody>
                                                </table>


                                            </empty>
                                            <!-- /.box-body -->
                                        </div>
                                        <!-- /.box -->
                                    </div>
                                    <!-- /.user-block -->
                                    <p> &nbsp;
                                    </p>
                                    <ul class="list-inline">
                                    </ul>

                                </div>
                                <!-- /.post -->

                            </div>

                        </div>
                        <!-- /.tab-content -->
                    </div>
                </div>
            </div>

        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->


    <div class="modal   fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">WiFi下挂终端列表</h4>
                </div>
                <div class="modal-body" id="stainfotr">


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>




    <include file="./Application/Home/View/Tpl/footer.html" />


    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->
<input type="hidden" id="wzwifiname" name="wzwifiname">

<script type="text/javascript">

    $(function(){
        $('#search').click(function(){
            var sstxt=$('#filtertxt').val();
            $(".info-box").hide().filter(" :contains('"+sstxt+"')").show();
        });

        $(".getdistance").each(function(){
            $(this).html('距离['+Math.round(Math.pow(10,Math.abs(parseInt($(this).attr('signalstrength')))
                /(10*4))*10)/100 +'米] <i class="fa fa-repeat"></i>&nbsp;');
        });

        var interval;
        $(".getdistance").click(function(){
            var mac = $(this).attr('mac');
            var dis=$(this);
            $(this).html('获取中...');
            $.ajax({
                url : "{:U('/Home/scanwifi/getStrength','',false)}",
                type : "post",
                dataType : "json",
                data: {mac:mac},
                timeout:30000,
                success:function(result){
                    console.log(result);
                    if(result.signalstrength){
                        var sl=parseInt(result.signalstrength);
                        dis.html('距离['+Math.round(Math.pow
                        (10,Math.abs( sl)
                        /(10*4))*10)/100 +'米] <i class="fa fa-repeat"></i>&nbsp;');
                    }
                    //启动每秒定时刷新功能
                    clearInterval(interval);
                    interval=window.setInterval(getcurrentdistence, 2000);
                    function getcurrentdistence( )
                    {
                        dis.html('获取中...');
                        $.ajax({
                            url : "{:U('/Home/scanwifi/getStrength','',false)}",
                            type : "post",
                            dataType : "json",
                            data: {mac:mac},
                            timeout:30000,
                            success:function(result){
                                console.log(result);
                                if(result.signalstrength){
                                    var sl=parseInt(result.signalstrength);
                                    dis.html('距离['+Math.round(Math.pow
                                    (10,Math.abs( sl)
                                        /(10*4))*10)/100 +'米] <i class="fa fa-repeat"></i>&nbsp;');
                                }
                            },
                            error:function(msg){
                                console.log(msg);      //执行错误
                            }
                        });
                    }
                },
                error:function(msg){
                    console.log(msg);      //执行错误
                }
            });
        });


        $(".getapsta").click(function(){
            var apmac = $(this).attr('apmac');
            $("#stainfotr").html('');
            $.ajax({
                url : "{:U('/Home/scanwifi/getdevlist','',false)}",
                type : "post",
                dataType : "json",
                data: {apmac:apmac},
                timeout:30000,
                success:function(result){
                    console.log(result);
                    if(result.status){
                        if(result.data.length==0){
                            $("#stainfotr").html('<span class="badge bg-red">该WiFi下没有扫描到下挂终端。</span>');
                            return;
                        }
                        var list="";
                        for(var iloop=0; iloop<result.data.length;iloop++){
                            list+="<tr class=\"stainfotrs\">\n" +
                                "        <td>"+ (iloop + 1) +"</td>\n" +
                                "        <td><span class=\"badge bg-red\">"+ result.data[iloop]['smac'] +"</span></td>\n" +
                                "        <td><span class=\"badge bg-green\">"+ result.data[iloop]['requsetSSID'] +"</span></td>\n" +
                                "        <td>"+ result.data[iloop]['devName'] + "</td>\n" +
                                "        <td>"+ result.data[iloop]['time'] + "</td>\n" +
                                "  </tr> ";
                        }

                        var tabdiv ="<table class=\"table table-bordered\">\n" +
                            "    <tbody><tr>\n" +
                            "     <th style=\"width: 10px\">编号</th>\n" +
                            "     <th>终端MAC地址</th>\n" +
                            "     <th>请求链接SSID</th>\n" +
                            "     <th >终端名称</th>\n" +
                            "     <th>捕获时间</th>\n" +
                            "\n" +
                            "    </tr>\n" +
                            "\n" +
                            "\n" + list +
                            "  </tbody></table>";

                        $("#stainfotr").append(tabdiv);
                    }
                    else {
                        $("#stainfotr").html('<span class="badge bg-red">该WiFi下没有扫描到下挂终端。</span>');
                    }
                },
                error:function(msg){
                    console.log(msg);      //执行错误
                }

            });
        });
    });

    $(".crackwifi").click(function(){
        var btn=$(this);
        var id = $(this).attr('myid');
        var xd = $(this).attr('xd');
        var apmac = $(this).attr('apmac');
        var action=$(this).attr('action');
        if(action=='start'){
            if($("#iscrack").val()==1){
                alert('已经在破解成其他设备，请先停止破解。');
                return;
            }
            btn.html('破解中... ...');
        }else{
            btn.html('破解停止中... ...');
        }

        $("#iscrack").val($("#iscrack").val()==0?1:0);
        $(this).attr('action', $(this).attr('action')=='start'?'stop':'start');

        var intervalcrack;
        $.ajax({
            url : "{:U('/Home/scanwifi/crackWiFi','',false)}",
            type : "post",
            dataType : "json",
            data: {id:id, xd: xd,apmac:apmac,action:action},
            timeout:30000,
            success:function(result){
                console.log(result);
                if(action=='start'){
                    btn.html('破解开启中... ...');
                    if(typeof(result.status) != "undefined" && result.status){
                        btn.html('破解进行中... ...');;

                        //定时任务获取破解结果
                        var iloop=0;
                        clearInterval(intervalcrack);
                        intervalcrack=window.setInterval(getcrackstatus, 2000);
                        function getcrackstatus( )
                        {
                            iloop++;
                            if(iloop>=1){
                                iloop=0;
                                btn.html('破解进行中... ...');
                            }
                            else{
                                btn.html('破解进行中... ');
                            }

                            $.ajax({
                                url : "{:U('/Home/scanwifi/getcrackWiFiStatus','',false)}",
                                type : "post",
                                dataType : "json",
                                data: {id:id},
                                timeout:30000,
                                success:function(result){
                                    console.log(result);
                                    if(result.status=='run'){

                                    }else if(result.status=='fail'){
                                        alert('破解失败：'+result.reason);

                                        btn.html('开启破解 ');
                                        $("#iscrack").val(0);
                                        btn.attr('action','start');
                                        clearInterval(intervalcrack);
                                    }else{
                                        alert('破解成功！密码：'+result.secret);
                                        btn.html('开启破解 ');
                                        $("#iscrack").val(0);
                                        btn.attr('action','start');
                                        $("#crackpwdval"+id).val(result.secret);
                                        $("#crackpwd"+id).html('(<small class=" ">密码：'+ result.secret +'</small>)');
                                        clearInterval(intervalcrack);
                                    }

                                },
                                error:function(msg){
                                    console.log(msg);      //执行错误
                                    $("#iscrack").val(0);
                                    btn.attr('action', 'start');
                                    if(action=='stop'){
                                        btn.html('开启破解');
                                    }else{
                                        btn.html('停止破解');
                                    }
                                }
                            });
                        }

                    }else {
                        alert('破解失败：'+result.reason);
                        btn.html('开启破解');
                        $("#iscrack").val(0);
                    }
                }else{
                    btn.html('开启破解');
                    $("#iscrack").val(0);
                }

            },
            error:function(msg){
                console.log(msg);      //执行错误
                $("#iscrack").val(0);
                $(this).attr('action', 'start');
                if(action=='start'){
                    btn.html('开启破解');
                }else{
                    btn.html('停止破解');
                }
            }

        });
    });


    $(".attackwifi").click(function(){
        var btn=$(this);
        var action=$(this).attr('action');
        if(action=='start'){
            if($("#isattack").val()==1){
                alert('已经在攻击成其他设备，请先停止攻击。');
                return;
            }
            btn.html('攻击启动中');
        }else{
            btn.html('攻击停止中');
        }

        $("#isattack").val($("#isattack").val()==0?1:0);
        $(this).attr('action', $(this).attr('action')=='start'?'stop':'start');

        var xd = $(this).attr('xd');
        var apmac = $(this).attr('apmac');
        $.ajax({
            url : "{:U('/Home/scanwifi/attackWiFi','',false)}",
            type : "post",
            dataType : "json",
            data: {xd: xd,apmac:apmac,action:action},
            timeout:30000,
            success:function(result){
                console.log(result);

                if(action=='start'){
                    btn.html('正在攻击中...');
                }else{
                    btn.html('开启攻击');
                }
            },
            error:function(msg){
                console.log(msg);      //执行错误
                if(action=='start'){
                    btn.html('开启攻击');
                }else{
                    btn.html('停止攻击');
                }
            }

        });
    });
    //xd="{$vo['signalPath']}" ssid="{$vo['ssid']}" encrypt="{$vo['encryption']}" key="" apmac="{$vo['mac']}"

    $(".wzwifi").click(function(){
        var id=$(this).attr('myid');
        var btn=$(this);
        var action=$(this).attr('action');
        if(action=='start'){
            if($("#iswz").val()==1){
                alert('已经伪装成其他设备，请先停止伪装。');

                return;
            }
            btn.html('伪装启动中');

        }else{
            btn.html('伪装停止中');
        }
        $("#iswz").val($("#iswz").val()==0?1:0);
        $(this).attr('action', $(this).attr('action')=='start'?'stop':'start');


        var xd = $(this).attr('xd');
        var ssid = $(this).attr('ssid');
        var encrypt = $(this).attr('encrypt');
        var key = $("#crackpwdval"+id).val()?$("#crackpwdval"+id).val():"12345678";
        var apmac = $(this).attr('apmac');
        $.ajax({
            url : "{:U('/Home/scanwifi/WZWifi','',false)}",
            type : "post",
            dataType : "json",
            data: {action:action, xd: xd, ssid:ssid,encrypt:encrypt,key:key, apmac:apmac},
            timeout:30000,
            success:function(result){
                console.log(result);

                if(action=='start'){
                    btn.html('正在伪装中');
                }else{
                    btn.html('开启伪装');
                }
            },
            error:function(msg){
                console.log(msg);      //执行错误
                if(action=='start'){
                    btn.html('开启伪装');
                }else{
                    btn.html('停止伪装');
                }
            }

        });
    });

    $.ajax({
        url : "{:U('/Home/scanwifi/getscanstatus','',false)}",
        type : "post",
        dataType : "json",
        data: null,
        timeout:3000,
        success:function(result){
            if(result.scanstatus=="runing"){
                $("#scanstatus").attr('action','stop');
                $("#scanstatus").html('停止扫描');
                $("#scanstatus").attr('class','btn pull-right  btn-success btn-lg');
            }
            else{
                $("#scanstatus").attr('action','start');
                $("#scanstatus").html('开启扫描');
                $("#scanstatus").attr('class','btn pull-right  btn-primary btn-lg');
            }
        },
        error:function(msg){
            console.log(msg);      //执行错误
            $("#scanstatus").attr('action','start');
            $("#scanstatus").html('扫描组件状态未知');
        }

    });
    $('#scanstatus').click(function () {
        var action=$(this).attr('action');
        $.ajax({
            url : "{:U('/Home/scanwifi/doscan','',false)}",
            type : "post",
            dataType : "json",
            data: {action:action},
            timeout:3000,
            success:function(result){
                if(result.status=="stop"){
                    $("#scanstatus").attr('action','stop');
                    $("#scanstatus").html('停止扫描');
                    $("#scanstatus").attr('class','btn pull-right  btn-success btn-lg');
                }
                else{
                    $("#scanstatus").attr('action','start');
                    $("#scanstatus").html('开启扫描');
                    $("#scanstatus").attr('class','btn pull-right  btn-primary btn-lg');
                }

            },
            error:function(msg){
                console.log(msg);      //执行错误
                $("#scanstatus").attr('action','start');
                $("#scanstatus").html('扫描组件状态未知');
            }

        });
    });

    $("#clearwifi").click(function(){
        $.ajax({
            url : "{:U('/Home/scanwifi/DatabaseClearAP','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:3000,
            success:function(result){
                console.log(result);
                $("#wifilist").remove();
                $('.scanwifidata').html('');
            },
            error:function(msg){
                console.log(msg);      //执行错误
                alert("系统错误!");
            }
        });

    });

    $("#clearsta").click(function(){
        $.ajax({
            url : "{:U('/Home/scanwifi/DatabaseClearSTA','',false)}",
            type : "post",
            dataType : "json",
            data: null,
            timeout:3000,
            success:function(result){
                console.log(result);
                $("#stalist").remove();
            },
            error:function(msg){
                console.log(msg);      //执行错误
                alert("系统错误!");
            }
        });
    });


</script>

</body>
</html>


